home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 August / Disc 1 / APC481.ISO / workshop / c / ascii.cpp next >
Encoding:
C/C++ Source or Header  |  1999-06-04  |  1.0 KB  |  42 lines

  1. // **************************************************************
  2. // ascii.cpp
  3. // Example program for Simple C++
  4. //
  5. // (c) 1999 Emmenjay Consulting Pty Ltd                          
  6. //                                                               
  7. // History                                                       
  8. // 04/06/99 MJS  Initial Coding.                                 
  9. //                                                               
  10. // **************************************************************
  11.  
  12. #include <iostream>
  13.  
  14. void PutASCII( int ch )
  15. {
  16.   std::cout.width( 4 );
  17.   std::cout << ch;
  18.   std::cout.width( 2 );
  19.   std::cout << char(ch) 
  20.             << "  ";
  21. }
  22.  
  23. void PutRow( int ch, int ncol, int offset )
  24. {
  25.   for (int i=0; i<ncol && ch<127; i++, ch+=offset)
  26.       PutASCII( ch );  
  27.   std::cout << '\n';
  28. }
  29.  
  30. int main( void )
  31. {
  32.   int ch;
  33.   int ncol = 6;
  34.   int offset = (127-32+ncol-1)/ncol;
  35.   int last   = 32+offset;
  36.  
  37.   for (ch=32; ch<last; ch++) 
  38.     PutRow( ch, ncol, offset );
  39.  
  40.   return 0;
  41. }
  42.